package com.tubeonfire.controller;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tubeonfire.model.PlaylistModel;

@SuppressWarnings("serial")
public class ListPlaylistServlet extends HttpServlet {

	private static final Logger log = Logger
			.getLogger(ListPlaylistServlet.class.getName());

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		try {
			int page = 1;
			try {
				page = Integer.parseInt((String) req.getParameter("page"));
			} catch (Exception e) {
				page = 1;
			}
			PlaylistModel model = new PlaylistModel();			
			model.setPage(page);
			model.prepareList(true);
			req.setAttribute("model", model);
			req.setAttribute("url", req.getRequestURL().toString());
			req.getRequestDispatcher("/list_playlist.jsp").forward(req, resp);
		} catch (Exception e) {
			log.warning(e.toString());
			e.printStackTrace();
			resp.sendError(4000,
					"Website is down for maintenance. We are sorry for the inconvenience !");
		}
	}
}
